/* 
 * File:   LowerCase.cpp
 * Author: maximiliano
 * 
 * Created on March 26, 2013, 5:43 PM
 */

#include "LowerCase.h"

using namespace TP3::Mangling;

LowerCase::LowerCase(int posIni, int posEnd) {
    _posIni = posIni;
    _posEnd = posEnd;
}

LowerCase::~LowerCase() {
}

string& LowerCase::run (string& operating){

    char aux [2] = {'\0','\0'}; 
    
    int posIni = _posIni;
    if (_posIni < 0)
        posIni = operating.length() + _posIni;
    
    int posEnd = _posEnd;    
    if (_posEnd < 0)
        posEnd = operating.length() + _posEnd;
    
    for (long int x = 0; x < (long int)operating.length(); x++)
    {
        if (posIni <= x && x <= posEnd)
        {
            aux [0] = operating.c_str()[x];

            if (65 <= (unsigned short int)aux[0] && (unsigned short int)aux [0] <= 65 + 26)
            {
                aux [0] = (char)((short int)aux [0]+ 32);
                operating = operating.replace(x, 1,aux);
            }
        }
    }
    
    return operating;
}

string LowerCase::getName() {
    
    return "lowercase";
}